package com.example.smart_city_0829.activity.sdkm;

import android.content.Context;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smart_city_0829.DeathData;
import com.example.smart_city_0829.R;
import com.example.smart_city_0829.base.BaseFragment;
import com.example.smart_city_0829.base.CommonAdapter;
import com.example.smart_city_0829.entity.sdkm.Kmlb;

import java.util.ArrayList;
import java.util.stream.Collectors;

public class XxlsFragment extends BaseFragment {

    private ListView lv;


    @Override
    protected int getLayoutId() {
        return R.layout.fragment_xxls;
    }

    @Override
    protected void initView() {
        lv = (ListView) rootView.findViewById(R.id.lv);

    }

    @Override
    protected void initData() {

        ArrayList<Kmlb> kmlbs = DeathData.yxgs.stream()
                .filter(Kmlb::getLearned).collect(Collectors.toCollection(ArrayList::new));
        kmlbs.addAll(DeathData.kmlb.stream()
                .filter(Kmlb::getLearned)
                .collect(Collectors.toList()));

        lv.setAdapter(new CommonAdapter<Kmlb, CommonAdapter.CommListViewHolder>(kmlbs,requireContext()) {
            @Override
            protected void setData(Kmlb data, int position, CommListViewHolder viewHolder, View convertView, Context context) {
                Glide.with(context)
                        .load(data.getPic())
                        .into(viewHolder.im);
                viewHolder.title.setText(data.getTitle());
                viewHolder.content.setText(data.getContent());
                viewHolder.tag1.setText(data.getName());
            }

            @Override
            protected CommListViewHolder getViewHolder() {
                return new CommListViewHolder();
            }

            @Override
            protected void initView(CommListViewHolder viewHolder, View convertView) {
                viewHolder.im = (ImageView) convertView.findViewById(R.id.im);
                viewHolder.title = (TextView) convertView.findViewById(R.id.title);
                viewHolder.content = (TextView) convertView.findViewById(R.id.content);
                viewHolder.tag1 = (TextView) convertView.findViewById(R.id.tag1);
                viewHolder.tag2 = (TextView) convertView.findViewById(R.id.tag2);
                viewHolder.tag3 = (TextView) convertView.findViewById(R.id.tag3);
            }
        });
    }

    @Override
    protected void initEvent() {

    }
}